package tsinghua.smxq.mc;

import tsinghua.smxq.foodprice.HistoryTable;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.Toast;

public class HistoryChartActivity extends Activity {
	private LinearLayout linearLayout;
	private String[][] items;
	String id, city, food, price;
	Toast toast;
	private Object oldLocale;
	HistoryTable historyTable;
	ImageButton mBtnChooseType = null;
	Button backToMain;

	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.historychart);
		linearLayout = (LinearLayout) findViewById(R.id.linearLayout_history);

		items = new String[][] { { "marketname", "城市" }, { "food", "食品" },
				{ "price", "价格" }, { "priceDate", "时间" } };

		historyTable = new HistoryTable(this, items, Constants.countPerPage);

		linearLayout.addView(historyTable);

		mBtnChooseType = (ImageButton) findViewById(R.id.ib_chooseType);
		mBtnChooseType.setOnClickListener(new Button.OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				new AlertDialog.Builder(HistoryChartActivity.this)
						.setTitle("菜价搜索功能")
						.setItems(new String[] { "菜价搜索", "菜价提交", "历史菜价" },
								new DialogInterface.OnClickListener() {

									@Override
									public void onClick(DialogInterface dialog,
											int which) {
										// TODO Auto-generated method stub
										if (which == 0) {
											Intent intent = new Intent();
											intent.setClass(
													HistoryChartActivity.this,
													FoodPriceRequestActivity.class);
											HistoryChartActivity.this
													.startActivity(intent);
										} else if (which == 1) {
											Intent intent = new Intent();
											intent.setClass(
													HistoryChartActivity.this,
													HistoryChartActivity.class);
											HistoryChartActivity.this
													.startActivity(intent);

										} else if (which == 2) {
											return;
										}

									}
								}).create().show();
			}

		});
		backToMain = (Button) findViewById(R.id.foodprice_records_back);
		backToMain.setOnClickListener(new Button.OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				HistoryChartActivity.this.startActivity(new Intent(
						HistoryChartActivity.this,
						FoodPriceRequestActivity.class));
				HistoryChartActivity.this.overridePendingTransition(
						R.anim.push_in, R.anim.push_out);
				HistoryChartActivity.this.finish();
			}

		});

	}

	public void DisplayToast(String str, int time) {
		toast = Toast.makeText(this, str, time);
		// 设置toast显示的位置
		toast.setGravity(Gravity.TOP, 0, 320);
		// 显示该Toast
		toast.show();
	}

}